home *** CD-ROM | disk | FTP | other *** search
- set output error
- set display page 23
- set more 1
- #delimit ;
-
- di _n(13) in wh
- " ___ ____ ____ ____ ____ tm" _n
- " /__ / ____/ / ____/" _n
- "___/ / /___/ / /___/ Data.Kit: Programmed Extensions to Stata" _n
- "-------------------------------------------------------------------------"
- _n(2) ;
-
- di in gr
- "Data.Kit is a collection of programs written in Stata that provides some useful"
- _n
- "data management commands. Although Data.Kit is written in Stata's programming"
- _n
- "language, you do not have to know anything about the programming language to"
- _n
- "use Data.Kit. We begin by loading the kit:" _n(2) ;
-
-
- #delimit cr
- mac def path
- capture run nullfile.tut
- if _rc {
- mac def path "\stata\"
- capture run %path`nullfile.tut
- if _rc {
- mac def path "/usr/stata/"
- capture run %path`nullfile.tut
- if _rc {
- #delimit ;
- di in red
- "I cannot find the other tutorial files. I have looked in the current" _n
- "directory and in \stata (DOS) or /usr/stata (Unix). Is Stata installed" _n
- "correctly?" _n(2)
- "In any case, I cannot run the tutorial." ;
- #delimit cr
- exit
- }
- }
- }
- macro define F5 "do %path`contents.tut;"
- macro define F6 "do %path`datakit.tut;"
-
- drop _all
- label drop _all
-
- #delimit ;
- di in wh ". run %path`Data.Kit" ;
- program drop _all ;
- run %path`Data.Kit ;
- di ; set more 0 ; more ; set more 1 ;
-
- di _n(2) in wh
- "Overview" _n
- "--------" _n ;
-
- di in gr
- "Data.Kit provides six new commands:" _n(2)
- _col(8) in wh "collapse" in gr _col(20)
- "make a data set of means, sums, or medians" _n
- _col(8) in wh "order" in gr _col(20)
- "change the order of the variables in a data set" _n
- _col(8) in wh "recast" in gr _col(20) "change the type of a variable" _n
- _col(8) in wh "mdytoe" in gr _col(20)
- "change month/day/year to elapsed date" _n
- _col(8) in wh "etomdy" in gr _col(20)
- "change elapsed date into month/day/year" _n
- _col(8) in wh "etodow" in gr _col(20)
- "calculate day-of-week corresponding to elapsed date" _n ;
-
- di in gr
- "We will not demonstrate them all here. At the conclusion of this tutorial,"
- _n
- "you might type '"
- in wh "help Data.Kit" in gr "' to learn more about the commands." ;
-
- di _n in gr
- "We were forced to omit the "
- in wh "order" in gr " command from the demonstration version of" _n
- "Data.Kit. During the process of making its calculations, "
- in wh "order" in gr " writes a" _n
- "temporary data set, something the demonstration version of Stata cannot do."
- _n
- "If you attempt to use "
- in wh "order" in gr ", you will get the message '" in ye "not available in" _n
- "demonstration version" in gr "'." _n(2)
- "If you are using the Unix version of Stata in demonstration mode, do not use"
- _n
- "the " in wh "order" in gr
- " command. Your version of Data.Kit contains the real " in wh "order"
- in gr " program," _n
- "but it will not work in demonstration mode." ;
- set more 0 ; more ; set more 1 ;
-
-
- di _n(9) in wh _dup(79) "-" _n in gr
- "Data.Kit's " in wh "collapse" in gr
- " command converts the data in memory into a data set of" _n
- "means or medians or sums. To illustrate this, we'll use our Census data:" _n
- in wh _dup(79) "-" _n(2)
- ". use %path`census.dta" ;
- noisily use %path`census.dta ;
- di _n in wh ". gen mrgrate = marriage/pop18p" ;
- gen mrgrate = marriage/pop18p ;
- di _n in wh ". gen dvcrate = divorce/pop18p" ;
- gen dvcrate = divorce/pop18p ;
- label var mrgrate "Marriage rate" ;
- label var dvcrate "Divorce rate" ;
- di _n in wh ". keep state region mrgrate dvcrate" ;
- keep state region mrgrate dvcrate ;
- di _n in wh ". describe" ;
- set more 0 ; more ; set more 1 ;
- noisily describe ;
- di _n in wh ". list in 1/8" ;
- noisily list in 1/8 ;
- set more 0 ; more ; set more 1 ;
-
- di _n(3) in wh _dup(79) "-" _n in gr
- "If all we wanted was to see the means by region, we would not need Data.Kit."
- _n
- "Stata's built-in "
- in wh "summarize" in gr " command combined with Stata's "
- in wh "by" in gr " prefix is all we"
- _n
- "need:" _n
- in wh _dup(79) "-" _n(2)
- ". sort region" ;
- sort region ;
- format mrgrate dvcrate %8.5f ;
- di _n in wh
- ". by region: summarize mrgrate dvcrate" ;
- set more 0 ; more ; set more 1 ;
- noisily by region: summarize mrgrate dvcrate ;
- set more 0 ; more ; set more 1 ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "We, however, want to make a data set of means:" _n
- in wh _dup(79) "-" _n(2)
- ". collapse mrgrate dvcrate, by(region) means" ;
- noisily collapse mrgrate dvcrate, by(region) nowarning means ;
- di _n in wh ". list" ;
- noisily list ;
- di ; set more 0 ; more ; set more 1 ;
-
- di _n(6) in wh _dup(79) "-" _n
- "mdytoe" in gr ", " in wh "etomdy" in gr ", and " in wh "etodow" in gr
- " are three date manipulation commands. " in wh "mdytoe" in gr " con-"
- _n
- "verts a date in month/day/year format into an elapsed date, defined as the" _n
- "number of days from "
- in ye "January 1, 1960" in gr ". " in wh "etomdy"
- in gr " converts an elapsed date back to" _n
- "month/day/year format and "
- in wh "etodow" in gr " derives the day-of-week (Sunday, Monday, Tues-" _n
- "day, etc.) from an elapsed date. The syntax of the commands is:" _n ;
-
- di _col(8) in wh "mdytoe " in gr "monthvar dayvar yearvar"
- in wh ", generate(" in gr "elapvar" in wh ")" _n(2)
- _col(8) "etomdy " in gr "elapvar" in wh ", generate("
- in gr "monthvar dayvar yearvar" in wh ")" _n(2)
- _col(8) "etodow " in gr "elapvar" in wh ", generate("
- in gr "dowvar" in wh ")" _n(2) in gr
- "This tutorial has silently loaded a data set containing some dates:" _n
- in wh _dup(79) "-" _n(4)
- ". list" ;
- drop _all ;
- input str10 event int(month day year) ;
- "Stata 1.0" 1 3 1985 ;
- "Stata 1.1" 2 1 1985 ;
- "Stata 1.2" 7 29 1985 ;
- "Stata 1.3" 9 23 1985 ;
- "Stata 1.4" 5 29 1986 ;
- "Stata 1.5" 4 17 1987 ;
- "Stata 2.0" 8 31 1988;
- end ;
- set more 0 ; more ; set more 1 ;
- noisily list ;
- di _n(3) in wh _dup(79) "-" _n in gr
- "We can use " in wh "mdytoe" in gr" to create an elapsed-date variable:" _n
- in wh _dup(79) "-" _n(3)
- ". mdytoe month day year, gen(elapsed)";
- mdytoe month day year, gen(elapsed) ;
- di _n in wh ". list" ;
- set more 0 ; more ; set more 1 ;
- noisily list ;
- di _n(2) in wh _dup(79) "-" _n in gr
- "We see that there are "
- in ye "9,134" in gr " days between January 1, 1960 and the release of" _n
- "the first version of Stata. There are "
- in ye "10,470" in gr " days until the release of Stata"
- _n
- "2.0. Elapsed dates are more convenient than month/day/year format because you"
- _n
- "can subtract them. There are, for instance, "
- in ye "10,470" in gr " - " in ye "9,134" in gr " = " in ye "1,336"
- in gr " days be-" _n
- "tween the release of Stata 1.0 and Stata 2.0." _n
- in wh _dup(79) "-" _n ;
- set more 0 ; more ; set more 1 ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "Once we have the elapsed dates, there is no reason to keep the month/day/year"
- _n
- "dates. We can always get them back using " in wh "etomdy" in gr ":" _n
- in wh _dup(79) "-" _n(4)
- ". drop month day year" _n(2)
- ". etomdy elapsed, generate(mo da yr)" ;
- drop month day year ;
- etomdy elapsed, generate(mo da yr) ;
- di _n in wh ". list" ;
- set more 0 ; more ; set more 1 ;
- noisily list ;
- di _n(2) in wh _dup(79) "-" _n in gr
- "The " in wh "etodow" in gr
- " command will derive the day-of-week from an elapsed date:" _n
- in wh _dup(79) "-" _n(2)
- ". etodow elapsed, generate(wkday)" ;
- etodow elapsed, generate(wkday) ;
- di _n in wh ". list" ;
- set more 0 ; more ; set more 1 ;
- noisily list ;
- di _n(6) ;
- drop _all ;
- label drop _all ;
- macro define F6 "do %path`qckit.tut;" ;
- set more 0 ; more ; set more 1 ;
-
- di _n(4) in white
- "Demonstration ends" _n
- "------------------" _n ;
-
-
- di in green
- "That concludes our short demonstration, but there's much more. We now return"
- _n
- "control to you. Some suggestions:" _n ;
-
- di in green
- "If you ..." _col(34) "Then we will show you ..." _n
- " Press " in white "F5" in green _col(38) "a table of tutorial contents" _n
- " Press " in white "F6" in green _col(38) "the next tutorial, "
- in white "qckit.tut" _n ;
-
- run %path`tobuy.tut ;